﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;
using com.lover.astd.common.model;

namespace com.lover.astd.common.logicexe.equip
{
    public class QhExe : ExeBase
    {
        public QhExe() { _name = ConfigStrings.S_Qh; _readable = ConfigStrings.SR_Qh; }
        public override void init_data() 
        {
            ServiceFactory.getEquipManager().getEquipmentsCanQh(_proto, _logger, _user, "");
            refreshUi();
        }
        public override long execute()
        {
            Dictionary<string, string> conf = getConfig();
            if (conf.ContainsKey(ConfigStrings.enabled) && conf[ConfigStrings.enabled].ToLower().Equals("true"))
            {
                bool use_gold = conf.ContainsKey(ConfigStrings.use_gold) && conf[ConfigStrings.use_gold].ToLower().Equals("true");
                int silver_limit = 1000000, assist_limit = 200000;
                if (conf.ContainsKey(ConfigStrings.use_gold_limit)) Int32.TryParse(conf[ConfigStrings.use_gold_limit], out silver_limit);
                if (conf.ContainsKey(ConfigStrings.qh_ids))
                {
                    string qh_ids = conf[ConfigStrings.qh_ids];
                    int result = 0;
                    do 
                    {
                        int silver_available = getSilverAvailable();
                        result = ServiceFactory.getEquipManager().handleEquipmentsCanQh(_proto, _logger, _user, 
                            silver_available, qh_ids, assist_limit, silver_limit);
                    }
                    while (result == 0);
                    refreshUi();
                }
            }
            return an_hour_later();
        }
    }
}
